package me.zhengjie.modules.system.service.dto

import cn.hutool.core.bean.BeanUtil
import cn.hutool.core.bean.copier.CopyOptions
import com.fasterxml.jackson.annotation.JsonInclude
import com.fasterxml.jackson.annotation.JsonTypeInfo
import com.fasterxml.jackson.annotation.JsonTypeName
import me.zhengjie.common.annotation.Query
import me.zhengjie.common.utils.JacksonUtil
import org.apache.commons.lang3.builder.ToStringBuilder

import java.sql.Timestamp
import java.time.LocalDateTime

/**
 * @author Kuki Wu
 * @date 2019-6-4 14:49:34
 */
@JsonTypeName("JobQueryCriteria")
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS)
data class JobQueryCriteria (
    @Query(type = Query.Type.INNER_LIKE)
    var name: String? = null,

    @Query
    var enabled: Boolean? = null,

    @Query(propName = "id", joinName = "dept")
    var deptId: Long? = null,


    @get:JsonTypeInfo(use = JsonTypeInfo.Id.CLASS)
    @get:JsonInclude(JsonInclude.Include.NON_EMPTY)
    @Query(propName = "id", joinName = "dept", type = Query.Type.IN)
    var deptIds: Set<Long>? = null,

    @Query(type = Query.Type.GREATER_THAN, propName = "createTime")
    var startTime: Timestamp? = null,

    @Query(type = Query.Type.LESS_THAN, propName = "createTime")
    var endTime: Timestamp? = null
){
    annotation class Update

    companion object {
        fun fromJson(json: String): JobQueryCriteria? {
            val obj=JacksonUtil.parseObject(json, JobQueryCriteria::class.java)!!
            return when(obj){
                is JobQueryCriteria -> obj
                else -> null
            }
        }
    }

    fun tojson():String? {
        return JacksonUtil.toJSONString(this)
    }

    fun copy(source: JobQueryCriteria?) {
        BeanUtil.copyProperties(source, this, CopyOptions.create().setIgnoreNullValue(true))
    }
}